package com.quanyan.stadium.service.gameRules.impl;

import com.quanyan.stadium.biz.BizGameSystemDao;
import com.quanyan.stadium.constants.GameConstants;
import com.quanyan.stadium.entity.TbGameEvent;
import com.quanyan.stadium.entity.TbGameEventTeam;
import com.quanyan.stadium.service.gameRules.GameRuleApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaoxiao on 16/12/16.
 *
 * 给外界提供等级分的一些操作
 */
@Service
public class GameRuleApiServiceImpl implements GameRuleApi{

    private final static Logger logger = LoggerFactory.getLogger(GameRuleApiServiceImpl.class);

    @Autowired
    private BizGameSystemDao bizGameSystemDao;

    @Autowired
    private GameRuleAllelicServiceImpl gameRuleAllelicService;

    @Autowired
    private GameRuleMixedServiceImpl gameRuleMixedService;

    @Override
    public void initGameRule(Integer gameEventId) {
        Map<String, Object> params = new HashMap<>();
        TbGameEvent tbGameEvent = bizGameSystemDao.selectTbGameEvent(gameEventId);
        Integer preGameRoundId = tbGameEvent.getCurrentRoundId();
        params.put("tbGameEvent", tbGameEvent);
        if (preGameRoundId > 0) {

        }else {
            initGameRound(gameEventId, params);
        }
        /*
        switch (tbGameEvent.getGameSystemType()) {
            case 1:
                //vDefinedGameSchedules = this.generateWashedCompList(tbGameRoundList, teamIds, reqChallenge, preGameRoundId);
                break;
            case 2:
                //vDefinedGameSchedules = this.generateCircleCompList(tbGameRoundList, teamIds, reqChallenge, tbGameEvent.getGameTeamType().intValue());
                break;
            case 3:
                //vDefinedGameSchedules = this.generateMixedCompList(tbGameRoundList, teamIds, reqChallenge, preGameRoundId);
                break;
            case 4:
                gameRuleAllelicService.createGameRound();
                //vDefinedGameSchedules = this.generateSwissCompList(tbGameRoundList, teamIds, reqChallenge, preGameRoundId);
                break;
            case 5:
                //vDefinedGameSchedules = this.generateUnsetCompList(teamIds, reqChallenge, preGameRoundId);
                break;
            case 6:
                //vDefinedGameSchedules = this.generateEightCompList(teamIds, reqChallenge, preGameRoundId);
                break;
            default:
                logger.debug("赛制不存在");
        }
        */
    }


    public void initGameRound(Integer gameEventId, Map<String, Object> params){
        TbGameEvent tbGameEvent = (TbGameEvent) params.get("tbGameEvent");
        List<TbGameEventTeam> tbGameEventTeamList = bizGameSystemDao.selectTbGameEventTeamByGameEventId(gameEventId, GameConstants.IS_NOT_DELETE);
        List<Integer> teamIds = new ArrayList<>();
        for (TbGameEventTeam tb : tbGameEventTeamList) {
            teamIds.add(tb.getId());
        }
        params.put("teamIds", teamIds);


        //对队伍对转换




        try {
            switch (tbGameEvent.getGameSystemType()) {
                case 1:
                    //vDefinedGameSchedules = this.generateWashedCompList(tbGameRoundList, teamIds, reqChallenge, preGameRoundId);
                    break;
                case 2:
                    //vDefinedGameSchedules = this.generateCircleCompList(tbGameRoundList, teamIds, reqChallenge, tbGameEvent.getGameTeamType().intValue());
                    break;
                case 3:
                    //vDefinedGameSchedules = this.generateMixedCompList(tbGameRoundList, teamIds, reqChallenge, preGameRoundId);
                    break;
                case 4:
                    gameRuleAllelicService.createGameRound(gameEventId, teamIds.size(), params);
                    break;
                case 5:
                    //vDefinedGameSchedules = this.generateUnsetCompList(teamIds, reqChallenge, preGameRoundId);
                    break;
                case 6:
                    //vDefinedGameSchedules = this.generateEightCompList(teamIds, reqChallenge, preGameRoundId);
                    break;
                default:
                    logger.debug("赛制不存在");
            }
        } catch (Exception e) {
            logger.debug("初始化轮次失败,当前赛事ID:{}", gameEventId);
        }
    }
}
